<template>
	<view class="mainpadding" v-if="pageShow" style="padding-bottom: 120rpx;">
		<view class="xiaohuang titletext bold" v-if="dataAll.status==1">复核员待审核</view>
		<view class="xiaohuang titletext bold" v-if="dataAll.status==2">主管待审核</view>
		<view class="xiaohuang titletext bold" v-if="dataAll.status==3">经理待审核</view>
		<view class="xiaohuang titletext bold" v-if="dataAll.status==4">待打款</view>
		<view class="xiaolv titletext bold" v-if="dataAll.status==5">已完成</view>
		<view class="xiaohong titletext bold" v-if="dataAll.status==6">审核失败</view>
		<view class="mainpadding_top ffffff radius">
			<view class="flexbetween">
				<view class="xiaohong bold titletext">{{dataAll.type.name}}</view>
				<view class="xiaohei main_size margin_top2 bold">￥{{dataAll.price}}</view>
			</view>
			<view class="xiaohui main_size margin_top2">{{dataAll.des}}</view>
			<view class="flexleft flex_wrap">
				<view class="sanshis flexcenter" v-for="(item,index) in dataAll.image_text" :key="index"
					@click="lbtpriview(index,dataAll.image_text)">
					<view class="dingwei margin_top" style="width: 180rpx;height: 180rpx;">
						<image :src="item" class=" radius" style="width: 100%;height: 100%;" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="xiaohei titletext bold">其他信息</view>
			<view class="flexbetween margin_top">
				<view class="xiaohei main_size">创建时间</view>
				<view class="xiaohui main_size">{{dataAll.createtime_text}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="xiaohei main_size">申请人</view>
				<view class="xiaohui main_size">{{dataAll.user.username}}</view>
			</view>
			<view class="" v-if="dataAll.jlsh_bz">
				<view class="flexbetween">
					<view class="xiaohei margin_top main_size">经理审核备注</view>
					<view class="xiaohong margin_top main_size">{{dataAll.bxjl.username}}</view>
				</view>
				<view class="xiaohui main_size margin_top">{{dataAll.jlsh_bz}}</view>
				<view class="xiaohui main_size margin_top">审核时间：{{dataAll.bxjltime_text}}</view>
			</view>
			<!-- 状态:1=复核员待审核,2=主管待审核,3=经理待审核,4=待打款,5=已完成,6=审核失败 -->
			<view class="pdl" v-if="dataAll.fhsh_bz">
				<view class="flexbetween">
					<view class="xiaohei margin_top main_size">复核员审核备注</view>
					<view class="xiaohong margin_top main_size">{{dataAll.bxfhy.username}}</view>
				</view>
				<view class="xiaohui main_size margin_top">{{dataAll.fhsh_bz}}</view>
				<view class="xiaohui main_size margin_top">审核时间：{{dataAll.bxfhytime_text}}</view>
			</view>
			<!-- <view class="pdl" v-if="dataAll.zgsh_bz">
				<view class="flexbetween">
					<view class="xiaohei margin_top main_size">主管审核备注</view>
					<view class="xiaohong margin_top main_size">{{dataAll.bxzg.username}}</view>
				</view>
				<view class="xiaohui main_size margin_top">{{dataAll.zgsh_bz}}</view>
				<view class="xiaohui main_size margin_top">审核时间：{{dataAll.bxzgtime_text}}</view>
			</view> -->
			<!-- <view class="pdl" v-if="dataAll.jlsh_bz">
				<view class="flexbetween">
					<view class="xiaohei margin_top main_size">经理审核备注</view>
					<view class="xiaohong margin_top main_size">{{dataAll.bxjl.username}}</view>
				</view>
				<view class="xiaohui main_size margin_top">{{dataAll.jlsh_bz}}</view>
				<view class="xiaohui main_size margin_top">审核时间：{{dataAll.bxjltime_text}}</view>
			</view> -->
			
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="xiaohei titletext bold">复核员审核信息</view>
			<view class="" v-for="item in dataAll.apply_data1" :key="item.id">
				<view class="flexbetween margin_top">
					<view class="xiaohei main_size">姓名</view>
					<view class="xiaohui main_size">{{item.user.username}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="xiaohei main_size">审核操作</view>
					<view class="xiaohong main_size" v-if="item.status==1">待审核</view>
					<view class="xiaohong main_size" v-if="item.status==2">已同意</view>
					<view class="xiaohong main_size" v-if="item.status==3">审核拒绝</view>
					<view class="xiaohong main_size" v-if="item.status==4">退回</view>
				</view>
				<view class="margin_top" v-if="item.status!=1">
					<text class="xiaohei main_size">审核备注：</text>
					<text class="xiaohui main_size">{{item.apply_bz}}</text>
				</view>
				<view class="flexbetween margin_top" v-if="item.status!=1">
					<view class="xiaohei main_size">审核时间</view>
					<view class="xiaohui main_size">{{item.apply_time_text}}</view>
				</view>
			</view>

		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="xiaohei titletext bold">经理审核信息</view>
			<view class="" v-for="item in dataAll.apply_data3" :key="item.id">
				<view class="flexbetween margin_top">
					<view class="xiaohei main_size">姓名</view>
					<view class="xiaohui main_size">{{item.user.username}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="xiaohei main_size">审核操作</view>
					<view class="xiaohong main_size" v-if="item.status==1">待审核</view>
					<view class="xiaohong main_size" v-if="item.status==2">已同意</view>
					<view class="xiaohong main_size" v-if="item.status==3">审核拒绝</view>
					<view class="xiaohong main_size" v-if="item.status==4">退回</view>
				</view>
				<view class="margin_top" v-if="item.status!=1">
					<text class="xiaohei main_size">审核备注：</text>
					<text class="xiaohui main_size">{{item.apply_bz}}</text>
				</view>
				<view class="flexbetween margin_top" v-if="item.status!=1">
					<view class="xiaohei main_size">审核时间</view>
					<view class="xiaohui main_size">{{item.apply_time_text}}</view>
				</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff radius" v-if="dataAll.dk_image_text">
			<view class="xiaohei titletext bold">打款审核信息</view>
			<view class="flexbetween">
				<view class="xiaohei margin_top main_size">打款凭证</view>
				<view class="xiaohong margin_top main_size">{{dataAll.bxdk.username}}</view>
			</view>
			<view class="flexleft flex_wrap">
				<view class="sanshis flexcenter">
					<view class="dingwei margin_top" style="width: 180rpx;height: 180rpx;"
						@click="lbtpriview(0,[dataAll.dk_image_text])">
						<image :src="dataAll.dk_image_text" class=" radius" style="width: 100%;height: 100%;"
							mode=""></image>
					</view>
				</view>
			</view>
			<view class="xiaohui main_size margin_top">审核时间：{{dataAll.bxdktime_text}}</view>
		</view>
		<view class="posibottom mainpadding">
			<view class="flexright" v-if="type==1 && dataAll.status==1">
				<view class="flexleft editbtn margin_right1"
					@click.stop="jumpdetail('/pages/tab4/baoxiaosq?id=',dataAll.id)">
					<u-icon name="edit-pen" color="#fff" size="16"></u-icon>
					<view class="xiaobai margin_left1 main_size">编辑</view>
				</view>
				<view class="flexleft trashbtn" @click.stop="currentid=dataAll.id;modal.modalShow=true">
					<u-icon name="trash" color="#c1282e" size="16"></u-icon>
					<view class="xiaohong margin_left1 main_size">删除</view>
				</view>
			</view>
			<view class="flexright" v-if="type==2">
				<view class="flexleft editbtn margin_right1" v-if="returnshow(dataAll)" @click.stop="shenhe(dataAll)">
					<u-icon name="file-text" color="#fff" size="16"></u-icon>
					<view class="xiaobai margin_left1 main_size">审核</view>
				</view>
			</view>
		</view>
		<u-modal :show="show" title="审核" confirm-text="确认" confirmColor="#c1282e" @confirm="shenheFn()" cancel-text="取消"
			@cancel="show=false" show-cancel-button>
			<view class="slot-content" style="width: 600rpx;">
				<view class="flexbetween pdl margin_top">
					<view class="main_size bold hei_text">状态：</view>
					<view class="flexright">
						<u-radio-group v-model="status" placement="row" circle>
							<u-radio activeColor="#c1282e" label="通过" :customStyle="{marginRight: '30rpx'}"
								name="normal"></u-radio>
							<u-radio activeColor="#c1282e" label="退回" name="hidden"
								:customStyle="{marginRight: '30rpx'}"></u-radio>
							<u-radio activeColor="#c1282e" label="拒绝" name="fail"></u-radio>
						</u-radio-group>
					</view>
				</view>
				<view class="margin_top flexbetween" @click="ryshow=true" v-if="successstatus==2">
					<view class="xiaohei main_size">抄送经理</view>
					<view class="flexright">
						<input type="text" placeholder="点击选择抄送经理" disabled="" class="xiaohei textright margin_right1 main_size"
							v-model="selectbqtext">
						<u-icon name="arrow-right" color="#333" size="16"></u-icon>
					</view>
				</view>
				<view class="margin_top"
					v-if="(successstatus==5 && status=='hidden') ||(successstatus==5 && status=='fail') || successstatus!=5">
					<view class="xiaohei main_size">审核备注</view>
					<textarea placeholder="请输入审核备注" class="xiaohei margin_top main_size" v-model="content"
						style="width: 100%;height: 120rpx;"></textarea>
				</view>
				<view class="margin_top" v-else>
					<view class="xiaohei main_size">凭证上传</view>
					<view class="flexleft flex_wrap">
						<view class="sanshis flexcenter" @click="uploadImg()" v-if="image!=''">
							<view class=" margin_top" style="width: 180rpx;height: 180rpx;position: relative;">
								<image :src="image_text" class=" radius" style="width: 100%;height: 100%;" mode="">
								</image>
							</view>
						</view>
						<view class="sanshis  flexcenter" @click="uploadImg()" v-if="image==''">
							<image src="@/static/tjtp.png" class="margin_top" style="width: 180rpx;height: 180rpx;"
								mode="">
							</image>
						</view>
					</view>
				</view>
			</view>
		</u-modal>
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
		<u-popup :show="ryshow" @close="ryshow=false">
			<view class="mainpadding ">
				<view class="mainpadding2 textcenter xiaohei main_size" style="padding-bottom: 0;">抄送经理</view>
				<view class="flexleft flex_wrap">
					<view :class="item.ischeck?'lvbtn margin_right margin_top1':'huibtn margin_right margin_top1'"
						v-for="item in ryList" :key="item.id" @click="checkssbq(item)">{{item.username}}</view>
				</view>
				<view class="margin_top submitbtn" @click="ssbqListfn()">确定</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				listid: "",
				type: 1, //1申请进入详情，2审批进入详情
				show: false,
				status: "normal",
				dataAll: {},
				pageShow: false,
				modal: {
					modalShow: false,
					title: "是否确认删除当前数据？",
				},
				currentid: "",
				userinfo: {},
				successstatus: 1,
				content: "",
				image: "",
				image_text: "",
				ryshow: false,
				ryList: [],
				selectbqtext: ""
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.type = options.type
			this.getInfo()
			this.getry()
		},
		onShow() {
			this.getDetail()
		},
		methods: {
			getry(data) {
				httpRequest.request("/api/user/getApplyBxUser", 'GET', {
					type: 3
				}).then(res => {
					res.data.forEach(item => {
						this.$set(item, "ischeck", false)
					})
					this.ryList = res.data
				})
			},
			checkssbq(item) {
				item.ischeck = !item.ischeck
			},
			ssbqListfn() {
				this.ryshow = false
				let arr = []
				this.ryList.forEach(item => {
					if (item.ischeck) {
						arr.push(item.username)
					}
				})
				this.selectbqtext = arr.length ? arr.join() : ""
			},
			shenheFn() {
				if (this.successstatus != 5 || (this.successstatus == 5 && this.status == 'hidden') || (this
						.successstatus == 5 && this.status == 'fail')) {
					if (this.content == "") {
						httpRequest.toast("请输入审核备注")
						return false
					}
				}
				if (this.successstatus == 5 && this.status == 'normal' && this.image == "") {
					httpRequest.toast("请上传打款凭证")
					return false
				}
				let data = {
					id: this.currentid,
					status: this.status == "normal" ? 2:this.status == "hidden" ? 4:3,
					bz:this.content
				}
				let apply_data = []
				this.ryList.forEach(item => {
					if (item.ischeck) {
						apply_data.push({
							type: 3,
							user_id: item.id
						})
						item.ischeck = false
					}
				})
				if (this.successstatus == 2) { //复核员审核
					// this.$set(data, 'fhsh_bz', this.content)
					this.$set(data, 'apply_data', apply_data)
				}
				// if (this.successstatus == 3) { //主管审核
				// 	this.$set(data, 'zgsh_bz', this.content)
				// }
				// if (this.successstatus == 4) { //经理审核
				// 	this.$set(data, 'jlsh_bz', this.content)
				// }
				if (this.successstatus == 5) { //打款审核
					this.$set(data, 'dk_image', this.image)
				}
				this.status = "normal"
				this.content = ""
				this.image = ""
				this.show = false
				httpRequest.request("/api/baoxiao/applyBaoxiao1", 'POST', data).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.getDetail()
					}
				})
			},
			shenhe(item) {
				this.show = true
				this.currentid = item.id
				if (item.status == 1) this.successstatus = 2
				if (item.status == 2) this.successstatus = 3
				if (item.status == 3) this.successstatus = 4
				if (item.status == 4) this.successstatus = 5
			},
			returnshow(item) {
				if(item.status==1 && item.btndata.fhy_apply==1) return true//复核员待审核
				if(item.status==2 && this.userinfo.is_bxzg==1) return true//主管待审核
				if(item.status==3 && item.btndata.jl_apply==1) return true//经理待审核
				if(item.status==4 && this.userinfo.is_bxdk==1) return true
			},
			uploadImg(value, upImgs, upImgs_text) { //上传图片
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			delindex(index, upImg, upImgs_text) {
				upImg.splice(index, 1)
				upImgs_text.splice(index, 1)
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.image = res.url
					this.image_text = image_item
				}).catch(err => {});
			},
			getInfo() {
				httpRequest.request("/api/user/getUerInfo", 'GET', {}).then(res => {
					this.userinfo = res.data
				})
			},
			modalSure() {
				if (this.modal.title == "是否确认删除当前数据？") {
					httpRequest.request("/api/baoxiao/delBaoxiao", 'GET', {
						id: this.currentid
					}).then(res => {
						httpRequest.toast(res.msg)
						if (res.code == 1) {
							setTimeout(() => {
								uni.navigateBack(1)
							}, 1000)
						}
					})
				}
				this.modalcancel()
			},
			modalcancel() {
				this.modal.modalShow = false
			},
			getDetail() {
				httpRequest.request("/api/baoxiao/baoxiaoDetail", 'GET', {
					id: this.listid
				}).then(res => {
					this.dataAll = res.data
					this.pageShow = true
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.editbtn {
		padding: 10rpx 30rpx;
		border-radius: 10rpx;
		background-color: #c1282e;
	}

	.trashbtn {
		padding: 10rpx 30rpx;
		border-radius: 10rpx;
		border: 1rpx solid #c1282e;
	}

	::v-deep .u-transition {
		z-index: 100 !important;
	}
</style>
<style lang="scss" scoped>
	.lvbtn {
		background: #DFFFED;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		padding: 10rpx 15rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #fff;
		background-color: #c1282e;
	}

	.huibtn {
		background: #F9F9F9;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		padding: 10rpx 15rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #777777;
	}
</style>